package utils

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
)

func GetOptions() (opts []grpc.ServerOption) {
	// 定义UnaryInterceptor的集合
	var unaryInts []grpc.UnaryServerInterceptor
	//定义流式拦截器的集合
	//var streamInts []grpc.StreamServerInterceptor
	//opts = make([]grpc.ServerOption, 0)
	unaryInts = append(unaryInts, UnaryInterceptor)
	unaryInts = append(unaryInts, UnaryInterceptor2)
	grpcOpts := []grpc.ServerOption{grpc.ChainUnaryInterceptor(unaryInts...)}
	//添加拦截器
	return grpcOpts
}

// 添加普通的拦截器
func UnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
	fmt.Println("server UnaryInterceptor:", info)
	return handler(ctx, req)
}

func UnaryInterceptor2(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
	fmt.Println("server UnaryInterceptor22222:", info)
	return handler(ctx, req)
}
